/*    */ package com.zimbra.cs.service.admin;
/*    */ 
/*    */ import com.google.common.base.Strings;
/*    */ import com.zimbra.common.account.Key.UCServiceBy;
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.AdminConstants;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.cs.account.AccessManager.AttrRightChecker;
/*    */ import com.zimbra.cs.account.AccountServiceException;
/*    */ import com.zimbra.cs.account.AttributeClass;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import com.zimbra.cs.account.UCService;
/*    */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*    */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ import java.util.Set;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class GetUCService
/*    */   extends AdminDocumentHandler
/*    */ {
/*    */   public Element handle(Element request, Map<String, Object> context)
/*    */     throws ServiceException
/*    */   {
/* 45 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/* 46 */     Provisioning prov = Provisioning.getInstance();
/*    */     
/* 48 */     Set<String> reqAttrs = getReqAttrs(request, AttributeClass.ucService);
/*    */     
/* 50 */     Element eUCService = request.getElement("ucservice");
/* 51 */     String by = eUCService.getAttribute("by");
/* 52 */     String name = eUCService.getText();
/*    */     
/* 54 */     if (Strings.isNullOrEmpty(name)) {
/* 55 */       throw ServiceException.INVALID_REQUEST("must specify a value for a uc service", null);
/*    */     }
/*    */     
/* 58 */     UCService ucService = prov.get(Key.UCServiceBy.fromString(by), name);
/*    */     
/* 60 */     if (ucService == null) {
/* 61 */       throw AccountServiceException.NO_SUCH_UC_SERVICE(name);
/*    */     }
/*    */     
/* 64 */     AdminAccessControl aac = checkRight(zsc, context, ucService, AdminRight.PR_ALWAYS_ALLOW);
/*    */     
/*    */ 
/* 67 */     prov.reload(ucService);
/*    */     
/* 69 */     Element response = zsc.createElement(AdminConstants.GET_UC_SERVICE_RESPONSE);
/* 70 */     encodeUCService(response, ucService, reqAttrs, aac.getAttrRightChecker(ucService));
/*    */     
/* 72 */     return response;
/*    */   }
/*    */   
/*    */   public static void encodeUCService(Element e, UCService s, Set<String> reqAttrs, AccessManager.AttrRightChecker attrRightChecker) throws ServiceException
/*    */   {
/* 77 */     Element eUCService = e.addElement("ucservice");
/* 78 */     eUCService.addAttribute("name", s.getName());
/* 79 */     eUCService.addAttribute("id", s.getId());
/* 80 */     Map<String, Object> attrs = s.getUnicodeAttrs();
/*    */     
/* 82 */     ToXML.encodeAttrs(eUCService, attrs, reqAttrs, attrRightChecker);
/*    */   }
/*    */   
/*    */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*    */   {
/* 87 */     relatedRights.add(Rights.Admin.R_getUCService);
/* 88 */     notes.add(String.format("Attributes that are not allowed to be get by the authenticated admin will be returned as <a n=\"{attr-name}\" pd=\"1\"/>.To allow an admin to get all attributes, grant the %s right", new Object[] { Rights.Admin.R_getUCService.getName() }));
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/GetUCService.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */